home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: Jens M Andreasen <jens-and@dsv.su.se>
- Newsgroups: comp.std.c,comp.lang.c.moderated
- Subject: Re: Integral promotion.
- Date: 21 Feb 1996 17:55:06 -0600
- Organization: Digital Solutions
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4ggbcq$81c@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
-
-
- On 21 Feb 1996, S. Lee wrote:
-
- > >> The addition operator "+" converts your short operands to ints.
- > >
- > >No, just using their values does that ...
-
- > Okay, I'm confused. Let just say the above is true. Then the expression
- > "x1 + x2" has type int because x1 and x2 were converted to int before
- > being passed to the + operator.
-
- I admit that I am confused too. So in this case the compiler should issue a
- warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both
- "x" and "1" are promoted to integers, and there could therefore be a
- potential loss of precision because "sizeof(int) > sizeof(short)", but no
- precision could have been lost if int and short had been the same (small)
- size ?? <phew>
-
- This again implies that the ++ operator should be avoided on short
- since it is destined to cause havoc and confusion ... Which in turn is
- not the way C is written ... (Ehrm :)
-
- [testing] _I can't even cast my way out of this!?_
-
- problem_with(short i){
- assert(sizeof (int) > sizeof (short));
- return i++; /* Warning: Precision may be lost */
- }
-
- I never saw this in any textbook :-)
-
- // Jens M Andreasen
-